package com.google.code.swingonfire.utility.date;

import java.text.DateFormatSymbols;
import java.util.Calendar;
import java.util.Locale;

public class DateRenderInfoEraPart extends AbstractDateRenderInfoPart
{

    public DateRenderInfoEraPart(int length)
    {
        super(length);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected String getValue(Calendar calendar, DateFormatSymbols dateFormatSymbols, Locale locale)
    {
        int value = calendar.get(Calendar.ERA);
        String[] eras = dateFormatSymbols.getEras();
        String result = null;

        if ((eras != null) && (value < eras.length))
        {
            result = eras[value];
        }

        return (result != null) ? result : "";
    }

}
